import {FC, Key, useCallback, useEffect, useRef, useState} from "react";
import {Space, Button, message} from "antd";
import {useFormEffects} from '@formily/react';
import {onFormMount} from '@formily/core';
import {DynamicObjectAny} from "@ey-utils/utils/typings";
import {Input as AntdInput} from 'antd';

interface BtnProps {
    text?: string,
    onClick?: any;
    type?: string
}

interface BtnGroupProps<V = any> {
    onChange: (value: V, record?: DynamicObjectAny | DynamicObjectAny[]) => void;
    btns?: BtnProps[],
    editable?: boolean;
}

const BtnGroup: FC<BtnGroupProps>
    = ({
           onChange,
           editable = true,
           ...restProps
       }) => {
    const formRef = useRef<any>();
    const btns = restProps?.btns
    useFormEffects(() => {
        onFormMount((form) => {
            formRef.current = form;
        });
    });

    return (
        <>
            {
                editable ? (
                    <Space>
                        {
                            btns && btns.map((btn: BtnProps) => {
                                const {type = "primary", onClick, text = '刷新'} = btn
                                return <Button type={type} onClick={() => btn.onClick ? onClick() : null}>
                                    {text}
                                </Button>
                            })
                        }
                    </Space>
                ) : null
            }

        </>
    );
};

export default BtnGroup;
